package kcms.course.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import kcms.course.dao.CourseDao;
import kcms.db.CourseJiaoke;
import kcms.db.Shangke;
import kcms.db.User;
@Repository
public class CourseDaoImpl  extends HibernateDaoSupport implements CourseDao{
	@Resource
	private SessionFactory sessionFactory;
	@Resource
	public void setMySessionFactory(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	@SuppressWarnings("unchecked")
	public List<CourseJiaoke> getAllCourseTeachBy(User user){
	return (List<CourseJiaoke>)this.getHibernateTemplate().find("from CourseJiaoke c where c.tid=?" ,user.getId());
	}
	
	public CourseJiaoke getByCidCsn(String cid, String csn){
		return (CourseJiaoke)this.getHibernateTemplate().find("from CourseJiaoke c where c.cid=? and c.csn=?", cid,csn).get(0);
	}
	@SuppressWarnings("unchecked")
	public List<Shangke> getAllCoursesCidCsn(User u){
		return (List<Shangke>) this.getHibernateTemplate().find("from Shangke s where s.id.sid=?", u.getId());
	}
	@SuppressWarnings("unchecked")
	public List<CourseJiaoke> getAllCourseByCid(String cid){
		return (List<CourseJiaoke>) this.getHibernateTemplate().find("from CourseJiaoke c where c.cid=?", cid);
	}
}
